"""
@Date:2022/8/5
@author:Jingyu
@Description：长春安全-安全 查询，排序Demo
@other：
"""
import time
from selenium.webdriver.common.by import By

from frameworkTest.SuperFramwork import SuperFramwork


class FrameworkByRead(SuperFramwork):

    # 搜索框的搜索
    def menuRead(self, driver, xpath, text):  # xpath地址，text：搜索内容  state：是否开启连续搜索  0不开启，1开启    (此处可以扩展多条件搜索)
        driver.find_element(By.XPATH, xpath).send_keys(text)
        driver.find_element(By.XPATH,
                            '//*[@id="root"]/section/section/section/main/div/div[2]/div/div[1]/div/div/form/div/div/button').click()
        #                    //*[@id="root"]/section/section/section/main/div/div[2]/div/div[1]/div/form/div/div/button
        time.sleep(2)
        driver.find_element(By.XPATH,
                            '//*[@id="root"]/section/section/section/main/div/div[2]/div/div[2]/div[2]/span[1]').click()  # 清空
        time.sleep(2)

    # input框 表头搜索
    def liReadByInput(self, driver, sequence, text):
        driver.find_element(By.XPATH,
                            '/html/body/div[1]/section/section/section/main/div/div[2]/div/div[2]/div/div/div/div/div[2]/div[1]/div[1]/div[2]/div/div[2]/div[' + str(
                                sequence) + ']/div[1]/div/div/span/input').send_keys(
            text)
        driver.find_element(By.XPATH,
                            '//*[@id="root"]/section/section/section/main/div/div[2]/div/div[2]/div[2]/span[1]').click()  # 清空
        time.sleep(1)

    # option下拉框 搜索
    def liReadByOption(self, driver,xpath, ulXpath, text):  # ulXpath：/html/body/div[3]/div/div/div/ul
        driver.find_element(By.XPATH,
                            '/html/body/div[1]/section/section/section/main/div/div[2]/div/div[2]/div/div/div/div/div[2]/div[1]/div[1]/div[2]/div/div[2]/div[3]/div[1]/div/div/div/div/div').click()
        time.sleep(3)
        ul = driver.find_element(By.XPATH, ulXpath)
        time.sleep(2)
        li_list = ul.find_elements_by_xpath('li')
        for i in li_list:
            print(i.text)
            if i.text == text:
                i.click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '//*[@id="root"]/section/section/section/main/div/div[2]/div/div[2]/div[2]/span[1]').click()  # 清空
        time.sleep(1)

    # 排序
    def sortById(self, driver, sequence):  # sequence:列表的第几个
        if type(sequence) == int:
            driver.find_element(By.XPATH,
                                '/html/body/div[1]/section/section/section/main/div/div[2]/div/div[2]/div/div/div/div/div[2]/div[1]/div[1]/div[2]/div/div[1]/div[' + str(
                                    sequence) + ']/div[3]/div/span[1]').click()
            time.sleep(2)
        else:
            print("参数异常，非数字")

    def sortAll(self, driver, endNum):  # endNum:列表包含多少列
        if type(endNum) == int:
            for i in range(endNum + 2):
                if i >= 3:
                    driver.find_element(By.XPATH,
                                        '/html/body/div[1]/section/section/section/main/div/div[2]/div/div[2]/div/div/div/div/div[2]/div[1]/div[1]/div[2]/div/div[1]/div[' + str(
                                            i) + ']/div[3]/div/span[1]').click()
                    time.sleep(2)
        else:
            print("参数异常，非数字")
